package com.jxd.controller;

import com.jxd.model.Employee;
import com.jxd.model.Transportation;
import com.jxd.service.ITransportationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/transportation")
public class TransportationController {

    @Autowired
    private ITransportationService transportationService;

    @RequestMapping("/transportationList")
    public Map<String, Object> transportationList(@RequestBody Map<String, String> map) {
        Map<String, Object> map1 = transportationService.getAllTransportationList(map);
        return map1;
    }

    @RequestMapping("/transportationList01")
    public List<Transportation> transportationList01() {
        return transportationService.list();
    }


    @RequestMapping("/addTransportation")
    public String addTransportation(@RequestBody Transportation transportation) {
        boolean flag = transportationService.save(transportation);
        if (flag) {
            return "success";
        } else {
            return "error";
        }
    }

    @RequestMapping("/updateTransportation")
    public String updateTransportation(@RequestBody Transportation transportation) {
        boolean flag = transportationService.updateById(transportation);
        if (flag) {
            return "success";
        } else {
            return "error";
        }
    }

    @RequestMapping("/delTransportation")
    public String delTransportation(@RequestBody List<Integer> ids) {
        boolean flag = transportationService.removeByIds(ids);
        if (flag) {
            return "success";
        } else {
            return "error";
        }
    }

    @RequestMapping("/getTransportation/{id}")
    public Transportation getTransportation(@PathVariable int id) {
        return transportationService.getById(id);
    }

}
